﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRRSRoguelike.Managers;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using System.Drawing;

namespace RRRSRoguelike.Screens
{
    class QuitScreen:Screen
    {
        Panel MainPanel;
		bool YesNo;
        
        public QuitScreen()
        {
            PanelList.Add(new Panel(new Point(4, 3),
                  Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6)); 

            MainPanel =  PanelList[0];
        }

        public bool ShowYesNo(DungeonScreen ds)
        {
            YesNo = false;
            
            Show(ds);

            return YesNo;
        }
        
        public void Show(DungeonScreen ds)
        {
            Clear();

            MainPanel.Draw();

            MainPanel.Write(Properties.Strings.Quit,0,ConsoleColor.White,TextAlignment.Multi);
           
            ConsoleKey quit = Console.ReadKey(true).Key;
            if (quit.Equals(ConsoleKey.Y))
            {
                //Testing if this is needed
                //DungeonManager.Instance.gameOver = true;
                YesNo = true;
                ReplayScreen s = new ReplayScreen(ds);
                if (s.ShowYesNo())
                { 
                    //Do nothing and fall through
                }
                else
                {
                    //MainPanel.Draw();
                    //MainPanel.Write("See you later!");
                    //WaitKey();
                    //GameManager.Instance.Exit();
                    //DungeonManager.Instance.Initialize();
                    
                    GameManager.Instance.ScreenStack.Push(new MenuScreen());
                }
            }
            else
            {
                MainPanel.Clear();
                //MainPanel.Write("Keep playing");

                DungeonManager.Instance.ForceRedraw();
            }
            GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
        }
    }
}
